package org.log4jconfig.xml.editor.hyperlink;

import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;

/**
 * Hyperlink to an Appender in the same editor No merit @see :
 * org.springframework
 * .ide.eclipse.beans.ui.editor.hyperlink.NodeElementHyperlink ;-)
 * 
 */
@SuppressWarnings("restriction")
public class AppenderElementHyperlink implements IHyperlink {

	private final IRegion region;

	private final IStructuredDocumentRegion targetRegion;

	private final ITextViewer viewer;

	public AppenderElementHyperlink(IRegion hyperlinkRegion, IStructuredDocumentRegion target, ITextViewer viewer) {
		this.region = hyperlinkRegion;
		this.targetRegion = target;
		this.viewer = viewer;
	}

	public IRegion getHyperlinkRegion() {
		return region;
	}

	public String getTypeLabel() {
		return "Jump to appender";
	}

	public String getHyperlinkText() {
		return "Jump to appender";
	}

	public void open() {
		viewer.setSelectedRange(targetRegion.getStartOffset(), 0);
		viewer.revealRange(targetRegion.getStartOffset(), targetRegion.getLength());
	}

}
